﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using Microsoft.Win32;
using OSVDB_Model;

namespace OSVDB_Logic
{
    public class Watchlist
    {
        public Watchlist()
        {

        }

        public Collection<WatchApp> getList()
        {
            Collection<WatchApp> list = new Collection<WatchApp>();
            WatchApp app = new WatchApp(string.Empty, string.Empty);
            try
            {
                string[] keys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall").GetSubKeyNames();
                foreach (string key in keys)
                {
                    RegistryKey key1 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + key);
                    try
                    {
                        app = new WatchApp(string.Empty, string.Empty);
                        string appname = key1.GetValue("DisplayName").ToString();
                        app.Name = appname;

                        string version = key1.GetValue("DisplayVersion").ToString();
                        app.Version = version;
                    }
                    catch (Exception)
                    {

                    }
                    finally
                    {
                        if (app.Name != string.Empty)
                        {
                            list.Add(app);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                
                throw;
            }
            

            return list;
        }
    }
}
